# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=jsearch
pkgver=44.87cf9c1
pkgrel=5
pkgdesc='Simple script that grep infos from javascript files.'
arch=('any')
groups=('blackarch' 'blackarch-recon' 'blackarch-webapp')
url='https://github.com/incogbyte/jsearch'
license=('custom:unknown')
depends=('python' 'python-beautifulsoup4' 'python-requests')
makedepends=('git')
source=("git+https://github.com/incogbyte/$pkgname.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  ( set -o pipefail
    git describe --long --tags --abbrev=7 2>/dev/null |
      sed 's/\([^-]*-g\)/r\1/;s/-/./g' ||
    printf "%s.%s" "$(git rev-list --count HEAD)" \
      "$(git rev-parse --short=7 HEAD)"
  )
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  install -Dm 644 -t "$pkgdir/usr/share/doc/$pkgname/" README.md *.gif

  rm -r README.md requirements.txt *.gif include/

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec python $pkgname.py "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

